<%@ page contentType="text/html; charset=utf-8" %>

<%@ include file="common.jsp" %>
<%@ page import="java.util.*" %>

<jsp:useBean id="cart" scope="session" class="mypack.ShoppingCart"/>

<html>
    <head><title>TitleShoppingCart</title>
    <link href="CSS/style1.css" rel="stylesheet">
    </head><body>
 <table width="100%" border="0">
  <tr>
    <td><center>
      <table width="750" border="0" bgcolor="#FFFFFF">
        <tr>
          <td colspan="2" valign="top"><jsp:include page="banner.jsp"/></td>
        </tr>    
        <tr>
          <td>&nbsp;</td> </tr>
    <%
  String bookId = request.getParameter("Remove");
  if (bookId != null) {
    cart.remove(bookId);
    BookDetails book = bookDB.getBookDetails(bookId);
%>

<%}
if (request.getParameter("Clear") != null) {
  cart.clear();
}%>       
        <tr>
        <td width="73%" valign="top">
	<% // Print a summary of the shopping cart
  int num = cart.getNumberOfItems();
  if (num > 0) {
%>
<table width="100%" height="272"  border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="97%" height="220" valign="top">
			   <table width="100%" height="126"  border="0" cellpadding="0" cellspacing="0">

			    <tr>
                  <td valign="top">
				  
				  <table width="100%" height="59"  border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="86%" height="59" class="tableBorder_B"><img src="Images/ico_cart.gif" width="176" height="70"></td>
                    </tr>
                  </table>
                    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>
<table width="100%" height="48" border="1" align="center" cellpadding="0" cellspacing="0">
      <tr align="center" valign="middle" bgcolor="#CCCCCC">
        <td height="27" >编号</td>
        <td height="27" >书号</td>
        <td >书名</td>
        <td height="27">单价</td>
        <td height="27" >数量</td>
        <td height="27">金额</td>
        <td>删除</td>
      </tr> 
	<%int ii=0;
            Iterator i = cart.getItems().iterator();
            while (i.hasNext()) {
              ShoppingCartItem item = (ShoppingCartItem)i.next();
              BookDetails book = (BookDetails)item.getItem();
              ii++;
%>

      <tr align="center" valign="middle"> 
        <td width="32" height="27"><%=ii%></td>
        <td width="109" height="27"><%=book.getBookid()%></td> 
        <td width="199" height="27"><%=book.getTitle()%></td>
        <td width="59" height="27">￥<%=book.getPrice()%></td> 
        <td width="51" height="27"><%=item.getQuantity()%> </td> 
        <td width="65" height="27">￥<%=(book.getPrice()*item.getQuantity())%></td> 
        <td width="34"><a href="<%=request.getContextPath()%>/showcart.jsp?Remove=<%=book.getBookid()%>"><img src="Images/del.gif" width="16" height="16"></a></td>
   	<%}%> </tr>
      </table>
	 
<table width="100%" height="52" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr align="center" valign="middle">
		<td height="10">&nbsp;		</td>
        <td width="24%" height="10" colspan="-3" align="left">&nbsp;</td>
		</tr>
      <tr align="center" valign="middle">
        <td height="21" class="tableBorder_B1">&nbsp;</td>
        <td height="21" colspan="-3" align="left" class="tableBorder_B1"><br><br>合计总金额：￥<%=cart.getTotal()%></td>
      </tr>
      <tr align="center" valign="middle">
        <td height="21" colspan="2"> <a href="<%=request.getContextPath()%>/catalog.jsp">继续购物</a> |<a href="<%=request.getContextPath()%>/cashier.jsp">去收银台结账</a> |<a href="<%=request.getContextPath()%>/showcart.jsp?Clear=clear">清空购物车</a></td>
        </tr>
</table>
</td>
 </tr>
   </table></td>
   </tr>
    </table>
 </td>
 <td width="3%" valign="top">&nbsp;</td>
            </tr>
          </table>
	<%}else{%>       

<table width="100%"  border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td height="70" colspan="2" class="tableBorder_B"><img src="Images/ico_cart.gif" width="176" height="70"></td>
                    </tr>
                    <tr>
                      <td height="24" colspan="2" align="center">&nbsp;</td>
                    </tr>
                    <tr>
                      <td width="48%" height="38" align="right" class="word_orange">您的购物车为空！</td>
                      <td width="52%" rowspan="3" align="right" valign="bottom"><img src="Images/cart.gif" width="150" height="186"></td>
                    </tr>
                    <tr>
                      <td height="57" align="right"><input name="Button" type="button" class="btn_grey" value="我要购书！" onClick="window.location.href='bookstore.jsp'"></td>
                    </tr>
                    <tr>
                      <td height="72" align="right">&nbsp;</td>
                    </tr>
                  </table>
<%
  }
%>
  </td>
      </tr>	
<tr><td height="16"><jsp:include page="copyright.jsp"/></td>
</tr>
     </table>
 </center></td>
  </tr>
</table>
</body>
</html>
